home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-15.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  3KB  |  78 lines

  1. ;
  2. ; *** Listing 7-15 ***
  3. ;
  4. ; Performs very fast bit-doubling of a byte in AL to a
  5. ; word in AX by using a look-up table.
  6. ; This approach avoids both branching and the severe
  7. ; instruction-fetching penalty of the shift-based approach.
  8. ;
  9. ; Macro to double each bit in a byte.
  10. ;
  11. ; Input:
  12. ;    AL = byte to bit-double
  13. ;
  14. ; Output:
  15. ;    AX = bit-doubled word
  16. ;
  17. ; Registers altered: AX, BX
  18. ;
  19. DOUBLE_BYTE    macro
  20.     mov    bl,al    ;move the byte to look up to BL,
  21.     sub    bh,bh    ; make a word out of the value,
  22.     shl    bx,1    ; and double the value so we can
  23.             ; use it as a pointer into the
  24.             ; table of word-sized doubled byte
  25.             ; values
  26.     mov    ax,[DoubledByteTable+bx]
  27.             ;look up the doubled byte value
  28.     endm
  29. ;
  30.     jmp    Skip
  31. DOUBLED_VALUE=0
  32. DoubledByteTable    label    word
  33.     dw    00000h,00003h,0000ch,0000fh,00030h,00033h,0003ch,0003fh
  34.     dw    000c0h,000c3h,000cch,000cfh,000f0h,000f3h,000fch,000ffh
  35.     dw    00300h,00303h,0030ch,0030fh,00330h,00333h,0033ch,0033fh
  36.     dw    003c0h,003c3h,003cch,003cfh,003f0h,003f3h,003fch,003ffh
  37.     dw    00c00h,00c03h,00c0ch,00c0fh,00c30h,00c33h,00c3ch,00c3fh
  38.     dw    00cc0h,00cc3h,00ccch,00ccfh,00cf0h,00cf3h,00cfch,00cffh
  39.     dw    00f00h,00f03h,00f0ch,00f0fh,00f30h,00f33h,00f3ch,00f3fh
  40.     dw    00fc0h,00fc3h,00fcch,00fcfh,00ff0h,00ff3h,00ffch,00fffh
  41. ;
  42.     dw    03000h,03003h,0300ch,0300fh,03030h,03033h,0303ch,0303fh
  43.     dw    030c0h,030c3h,030cch,030cfh,030f0h,030f3h,030fch,030ffh
  44.     dw    03300h,03303h,0330ch,0330fh,03330h,03333h,0333ch,0333fh
  45.     dw    033c0h,033c3h,033cch,033cfh,033f0h,033f3h,033fch,033ffh
  46.     dw    03c00h,03c03h,03c0ch,03c0fh,03c30h,03c33h,03c3ch,03c3fh
  47.     dw    03cc0h,03cc3h,03ccch,03ccfh,03cf0h,03cf3h,03cfch,03cffh
  48.     dw    03f00h,03f03h,03f0ch,03f0fh,03f30h,03f33h,03f3ch,03f3fh
  49.     dw    03fc0h,03fc3h,03fcch,03fcfh,03ff0h,03ff3h,03ffch,03fffh
  50. ;
  51.     dw    0c000h,0c003h,0c00ch,0c00fh,0c030h,0c033h,0c03ch,0c03fh
  52.     dw    0c0c0h,0c0c3h,0c0cch,0c0cfh,0c0f0h,0c0f3h,0c0fch,0c0ffh
  53.     dw    0c300h,0c303h,0c30ch,0c30fh,0c330h,0c333h,0c33ch,0c33fh
  54.     dw    0c3c0h,0c3c3h,0c3cch,0c3cfh,0c3f0h,0c3f3h,0c3fch,0c3ffh
  55.     dw    0cc00h,0cc03h,0cc0ch,0cc0fh,0cc30h,0cc33h,0cc3ch,0cc3fh
  56.     dw    0ccc0h,0ccc3h,0cccch,0cccfh,0ccf0h,0ccf3h,0ccfch,0ccffh
  57.     dw    0cf00h,0cf03h,0cf0ch,0cf0fh,0cf30h,0cf33h,0cf3ch,0cf3fh
  58.     dw    0cfc0h,0cfc3h,0cfcch,0cfcfh,0cff0h,0cff3h,0cffch,0cfffh
  59. ;
  60.     dw    0f000h,0f003h,0f00ch,0f00fh,0f030h,0f033h,0f03ch,0f03fh
  61.     dw    0f0c0h,0f0c3h,0f0cch,0f0cfh,0f0f0h,0f0f3h,0f0fch,0f0ffh
  62.     dw    0f300h,0f303h,0f30ch,0f30fh,0f330h,0f333h,0f33ch,0f33fh
  63.     dw    0f3c0h,0f3c3h,0f3cch,0f3cfh,0f3f0h,0f3f3h,0f3fch,0f3ffh
  64.     dw    0fc00h,0fc03h,0fc0ch,0fc0fh,0fc30h,0fc33h,0fc3ch,0fc3fh
  65.     dw    0fcc0h,0fcc3h,0fccch,0fccfh,0fcf0h,0fcf3h,0fcfch,0fcffh
  66.     dw    0ff00h,0ff03h,0ff0ch,0ff0fh,0ff30h,0ff33h,0ff3ch,0ff3fh
  67.     dw    0ffc0h,0ffc3h,0ffcch,0ffcfh,0fff0h,0fff3h,0fffch,0ffffh
  68. ;
  69. Skip:
  70.     call    ZTimerOn
  71. BYTE_TO_DOUBLE=0
  72.     rept    100
  73.     mov    al,BYTE_TO_DOUBLE
  74.     DOUBLE_BYTE
  75. BYTE_TO_DOUBLE=BYTE_TO_DOUBLE+1
  76.     endm
  77.     call    ZTimerOff
  78.